FROM golang:1.17-alpine AS builder

WORKDIR /workspace

RUN apk update \
    # Common command tools(Optional)
    && apk --no-cache add ca-certificates curl git wget unzip sshpass upx \
    && update-ca-certificates

RUN cd /workspace \
    && git clone https://gitee.com/gitee-go/server.git \
    && git clone https://gitee.com/gitee-go/utils.git \
    && git clone https://gitee.com/gitee-go/core.git \
    && git clone https://gitee.com/gitee-go/dag-core.git \
    && git clone https://gitee.com/gitee-go/runner.git \
    && git clone https://gitee.com/gitee-go/runner-core.git \
    && wget https://talk.gitee.com/gitee-go-oss/frontend.zip \
    && mkdir frontend \
    && unzip frontend.zip -d ./frontend \
    && cd server \
    && go run bdconts.go -d ../frontend \
    && go get -u github.com/jteeuwen/go-bindata/... \
    && go-bindata -o comm/migrate.go -pkg=comm -prefix migrates migrates/ \
    && cd ../server \
    && GOOS=linux GOARCH=386 go build -ldflags="-s -w" -o ../bin/server main.go \
    && cd ../runner \
    && GOOS=linux GOARCH=386 go build -ldflags="-s -w" -o ../bin/runner main.go \
    && upx -9 ../bin/server \
    && upx -9 ../bin/runner

FROM alpine AS giteego

RUN apk update \
    # Common command tools(Optional)
    && apk --no-cache add ca-certificates bash curl git wget unzip sshpass \
    && update-ca-certificates
COPY docker-entrypoint.sh /docker-entrypoint.sh
RUN mkdir /app && chmod +x /docker-entrypoint.sh
COPY --from=builder /workspace/bin/ /gitee_go_bin/

ENTRYPOINT ["sh","/docker-entrypoint.sh"] 